<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.utils.generic &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="up" title="gozerlib.utils" href="index.html" />
    <link rel="next" title="gozerlib.utils.lazydict" href="lazydict.html" />
    <link rel="prev" title="gozerlib.utils.exception" href="exception.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="lazydict.html" title="gozerlib.utils.lazydict"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="exception.html" title="gozerlib.utils.exception"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">gozerlib.utils</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.utils.generic">
<h1>gozerlib.utils.generic<a class="headerlink" href="#module-gozerlib.utils.generic" title="Permalink to this headline">¶</a></h1>
<p>generic functions.</p>
<dl class="function">
<dt id="gozerlib.utils.generic.decodeperchar">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">decodeperchar</tt><big>(</big><em>txt</em>, <em>encoding='utf-8'</em>, <em>what=''</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.decodeperchar" title="Permalink to this definition">¶</a></dt>
<dd>decode a string char by char. strip chars that can&#8217;t be decoded.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.filesize">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">filesize</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.filesize" title="Permalink to this definition">¶</a></dt>
<dd>return filesize of a file.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.fromenc">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">fromenc</tt><big>(</big><em>txt</em>, <em>encoding='utf-8'</em>, <em>what=''</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.fromenc" title="Permalink to this definition">¶</a></dt>
<dd>convert from encoding.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.gethighest">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">gethighest</tt><big>(</big><em>ddir</em>, <em>ffile</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.gethighest" title="Permalink to this definition">¶</a></dt>
<dd>get filename with the highest extension (number).</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.getrandomnick">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">getrandomnick</tt><big>(</big><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.getrandomnick" title="Permalink to this definition">¶</a></dt>
<dd>return a random nick.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.getversion">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">getversion</tt><big>(</big><em>txt=''</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.getversion" title="Permalink to this definition">¶</a></dt>
<dd>return a version string.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.getwho">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">getwho</tt><big>(</big><em>bot</em>, <em>nick</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.getwho" title="Permalink to this definition">¶</a></dt>
<dd>return userhost for nick. NOT IMPLEMENTED YET .. return the nick.</dd></dl>

<dl class="class">
<dt id="gozerlib.utils.generic.istr">
<em class="property">class </em><tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">istr</tt><a class="headerlink" href="#gozerlib.utils.generic.istr" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="(in Python v2.7)" class="reference external" href="http://docs.python.org/dev/library/functions.html#str"><tt class="xref docutils literal"><span class="pre">str</span></tt></a></p>
<p>convenience class to store attributes on a string.</p>
</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.jabberstrip">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">jabberstrip</tt><big>(</big><em>text</em>, <em>allowed=</em><span class="optional">[</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.jabberstrip" title="Permalink to this definition">¶</a></dt>
<dd>strip control characters for jabber transmission.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.jsonstring">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">jsonstring</tt><big>(</big><em>input</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.jsonstring" title="Permalink to this definition">¶</a></dt>
<dd>convert input to a json string.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.makeoptions">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">makeoptions</tt><big>(</big><em>ievent</em>, <em>options={}</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.makeoptions" title="Permalink to this definition">¶</a></dt>
<dd>create options from event.txt.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.plugfile">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">plugfile</tt><big>(</big><em>datadir</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.plugfile" title="Permalink to this definition">¶</a></dt>
<dd>return plugin file.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.plugnames">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">plugnames</tt><big>(</big><em>dirname</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.plugnames" title="Permalink to this definition">¶</a></dt>
<dd>return all plugin names of plugins in a directory.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.splittxt">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">splittxt</tt><big>(</big><em>what</em>, <em>l=375</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.splittxt" title="Permalink to this definition">¶</a></dt>
<dd>split output into seperate chunks.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.stringinlist">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">stringinlist</tt><big>(</big><em>s</em>, <em>l</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.stringinlist" title="Permalink to this definition">¶</a></dt>
<dd>check is string is in list of strings.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.stripped">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">stripped</tt><big>(</big><em>userhost</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.stripped" title="Permalink to this definition">¶</a></dt>
<dd>return a stripped userhost (everything before the &#8216;/&#8217;).</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.strippedtxt">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">strippedtxt</tt><big>(</big><em>what</em>, <em>allowed=</em><span class="optional">[</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.strippedtxt" title="Permalink to this definition">¶</a></dt>
<dd>strip control characters from txt.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.toascii">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">toascii</tt><big>(</big><em>what</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.toascii" title="Permalink to this definition">¶</a></dt>
<dd>convert to ascii.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.toenc">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">toenc</tt><big>(</big><em>what</em>, <em>encoding='utf-8'</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.toenc" title="Permalink to this definition">¶</a></dt>
<dd>convert to encoding.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.tolatin1">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">tolatin1</tt><big>(</big><em>what</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.tolatin1" title="Permalink to this definition">¶</a></dt>
<dd>convert to latin1.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.touch">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">touch</tt><big>(</big><em>fname</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.touch" title="Permalink to this definition">¶</a></dt>
<dd>touch a file.</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.uniqlist">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">uniqlist</tt><big>(</big><em>l</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.uniqlist" title="Permalink to this definition">¶</a></dt>
<dd>return unique elements in a list (as list).</dd></dl>

<dl class="function">
<dt id="gozerlib.utils.generic.waitforqueue">
<tt class="descclassname">gozerlib.utils.generic.</tt><tt class="descname">waitforqueue</tt><big>(</big><em>queue</em>, <em>timeout=10</em>, <em>maxitems=None</em><big>)</big><a class="headerlink" href="#gozerlib.utils.generic.waitforqueue" title="Permalink to this definition">¶</a></dt>
<dd>wait for results to arrive in a queue. return list of results.</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/utils/generic.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; generic functions. &quot;&quot;&quot;</span>

<span class="c">## gozerlib imports </span>

<span class="kn">from</span> <span class="nn">exception</span> <span class="kn">import</span> <span class="n">handle_exception</span>
<span class="kn">from</span> <span class="nn">trace</span> <span class="kn">import</span> <span class="n">calledfrom</span>
<span class="kn">from</span> <span class="nn">lazydict</span> <span class="kn">import</span> <span class="n">LazyDict</span>

<span class="c">## generic imports</span>

<span class="kn">from</span> <span class="nn">simplejson</span> <span class="kn">import</span> <span class="n">dumps</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">getopt</span>
<span class="kn">import</span> <span class="nn">types</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">Queue</span> 
<span class="kn">import</span> <span class="nn">logging</span>

<span class="k">def</span> <span class="nf">getwho</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">nick</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; return userhost for nick. NOT IMPLEMENTED YET .. return the nick. &quot;&quot;&quot;</span>

    <span class="k">return</span> <span class="n">nick</span>

<span class="k">def</span> <span class="nf">jsonstring</span><span class="p">(</span><span class="nb">input</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; convert input to a json string. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span> <span class="o">==</span> <span class="n">types</span><span class="o">.</span><span class="n">TupleType</span><span class="p">:</span>
        <span class="nb">input</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">dumps</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">getversion</span><span class="p">(</span><span class="n">txt</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; return a version string. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">rev</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s">&#39;TIP&#39;</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mf">1</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="n">rev</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>

    <span class="kn">import</span> <span class="nn">gozerlib</span>

    <span class="k">if</span> <span class="n">rev</span><span class="p">:</span>
        <span class="k">return</span> <span class="s">&quot;GOZERWAVE </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">) BETA </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">gozerlib</span><span class="o">.</span><span class="n">__version__</span><span class="p">,</span> <span class="n">rev</span><span class="p">,</span> <span class="n">txt</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="s">&quot;GOZERWAVE </span><span class="si">%s</span><span class="s"> BETA </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">gozerlib</span><span class="o">.</span><span class="n">__version__</span><span class="p">,</span> <span class="n">txt</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">makeoptions</span><span class="p">(</span><span class="n">ievent</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="p">{}):</span>

    <span class="sd">&quot;&quot;&quot; create options from event.txt. &quot;&quot;&quot;</span>

    <span class="n">options</span> <span class="o">=</span> <span class="n">LazyDict</span><span class="p">(</span><span class="n">options</span><span class="p">)</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">optargs</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
        <span class="n">optlist</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;--filter&#39;</span><span class="p">):</span>
            <span class="n">options</span><span class="p">[</span><span class="s">&#39;--filter&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;--to&#39;</span><span class="p">):</span>
            <span class="n">options</span><span class="p">[</span><span class="s">&#39;--to&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;--chan&#39;</span><span class="p">):</span>
            <span class="n">options</span><span class="p">[</span><span class="s">&#39;--chan&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">channel</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;--how&#39;</span><span class="p">):</span>
            <span class="n">options</span><span class="p">[</span><span class="s">&#39;--how&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;msg&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;--speed&#39;</span><span class="p">):</span>
            <span class="n">options</span><span class="p">[</span><span class="s">&#39;--speed&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">speed</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s">&#39;--speed&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;--speed&#39;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">options</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">if</span> <span class="s">&#39;--&#39;</span> <span class="ow">in</span> <span class="n">i</span><span class="p">:</span>
                <span class="n">optlist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">=&quot;</span> <span class="o">%</span> <span class="n">i</span><span class="p">[</span><span class="mf">2</span><span class="p">:])</span>
                <span class="k">if</span> <span class="n">j</span><span class="p">:</span>
                    <span class="n">optlist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>
                <span class="k">continue</span>
            <span class="k">if</span> <span class="s">&#39;-&#39;</span> <span class="ow">in</span> <span class="n">i</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">j</span><span class="p">:</span>
                    <span class="n">optargs</span> <span class="o">+=</span> <span class="s">&quot;:</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">i</span><span class="p">[</span><span class="mf">1</span><span class="p">:]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">optargs</span> <span class="o">+=</span> <span class="n">i</span><span class="p">[</span><span class="mf">1</span><span class="p">:]</span>
        <span class="n">args</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">txt</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">rest</span><span class="p">)</span> <span class="o">=</span> <span class="n">getopt</span><span class="o">.</span><span class="n">getopt</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mf">1</span><span class="p">:],</span> <span class="n">optargs</span><span class="p">,</span> <span class="n">optlist</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;option not allowed: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">),</span> <span class="n">ievent</span><span class="o">.</span><span class="n">txt</span><span class="p">,</span> <span class="n">options</span>
            <span class="k">return</span> <span class="mf">0</span>
        <span class="k">except</span> <span class="n">getopt</span><span class="o">.</span><span class="n">GetoptError</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">return</span> <span class="mf">0</span>
        <span class="k">if</span> <span class="n">opts</span><span class="p">:</span>
             <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">opts</span><span class="p">:</span>
                 <span class="n">ievent</span><span class="o">.</span><span class="n">optionset</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="mf">0</span><span class="p">])</span>
        <span class="n">o</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">options</span><span class="p">)</span>
        <span class="n">o</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">opts</span><span class="p">))</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="nb">filter</span> <span class="o">=</span> <span class="n">o</span><span class="p">[</span><span class="s">&#39;--filter&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="nb">filter</span> <span class="ow">and</span> <span class="nb">filter</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ievent</span><span class="o">.</span><span class="n">filter</span><span class="p">:</span>
                <span class="n">ievent</span><span class="o">.</span><span class="n">filter</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">filter</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">speed</span> <span class="o">=</span> <span class="n">o</span><span class="p">[</span><span class="s">&#39;--speed&#39;</span><span class="p">]</span>
            <span class="n">ievent</span><span class="o">.</span><span class="n">speed</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">speed</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">ievent</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="n">o</span><span class="p">[</span><span class="s">&#39;--chan&#39;</span><span class="p">]</span> <span class="ow">or</span> <span class="n">ievent</span><span class="o">.</span><span class="n">channel</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">args</span><span class="p">:</span>
            <span class="n">ievent</span><span class="o">.</span><span class="n">txt</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39; &#39;</span> <span class="o">+</span> <span class="s">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">rest</span><span class="p">)</span>
        <span class="n">makeargrest</span><span class="p">(</span><span class="n">ievent</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
        <span class="n">handle_exception</span><span class="p">()</span>
        <span class="k">return</span> 
    <span class="k">return</span> <span class="n">ievent</span><span class="o">.</span><span class="n">options</span>

<span class="k">def</span> <span class="nf">plugfile</span><span class="p">(</span><span class="n">datadir</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; return plugin file. &quot;&quot;&quot;</span>

    <span class="k">return</span> <span class="n">datadir</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="n">calledfrom</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">_getframe</span><span class="p">())</span>

<span class="k">def</span> <span class="nf">splittxt</span><span class="p">(</span><span class="n">what</span><span class="p">,</span> <span class="n">l</span><span class="o">=</span><span class="mf">375</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; split output into seperate chunks. &quot;&quot;&quot;</span>

    <span class="n">txtlist</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">start</span> <span class="o">=</span> <span class="mf">0</span>
    <span class="n">end</span> <span class="o">=</span> <span class="n">l</span>
    <span class="n">length</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">length</span><span class="o">/</span><span class="n">end</span><span class="o">+</span><span class="mf">1</span><span class="p">):</span>
        <span class="n">endword</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">endword</span> <span class="o">==</span> <span class="o">-</span><span class="mf">1</span><span class="p">:</span>
            <span class="n">endword</span> <span class="o">=</span> <span class="n">length</span>

        <span class="n">res</span> <span class="o">=</span> <span class="n">what</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">endword</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">res</span><span class="p">:</span>
            <span class="n">txtlist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>

        <span class="n">start</span> <span class="o">=</span> <span class="n">endword</span>
        <span class="n">end</span> <span class="o">=</span> <span class="n">start</span> <span class="o">+</span> <span class="n">l</span>

    <span class="k">return</span> <span class="n">txtlist</span>
    
<span class="k">class</span> <span class="nc">istr</span><span class="p">(</span><span class="nb">str</span><span class="p">):</span> 

    <span class="sd">&quot;&quot;&quot; convenience class to store attributes on a string. &quot;&quot;&quot;</span>

    <span class="k">pass</span>

<span class="k">def</span> <span class="nf">getrandomnick</span><span class="p">():</span>

    <span class="sd">&quot;&quot;&quot; return a random nick. &quot;&quot;&quot;</span>

    <span class="k">return</span> <span class="s">&quot;gwbot&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span> <span class="mf">100</span><span class="p">))</span>

<span class="k">def</span> <span class="nf">decodeperchar</span><span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&#39;utf-8&#39;</span><span class="p">,</span> <span class="n">what</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; decode a string char by char. strip chars that can&#39;t be decoded. &quot;&quot;&quot;</span>

    <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">nogo</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">txt</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">encoding</span><span class="p">))</span>
        <span class="k">except</span> <span class="ne">UnicodeDecodeError</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">i</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">nogo</span><span class="p">:</span>
                <span class="n">nogo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
            <span class="k">continue</span>

    <span class="k">if</span> <span class="n">nogo</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">what</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">: can&#39;t decode </span><span class="si">%s</span><span class="s"> characters to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">what</span><span class="p">,</span> <span class="n">nogo</span><span class="p">,</span> <span class="n">encoding</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;can&#39;t decode </span><span class="si">%s</span><span class="s"> characters to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">nogo</span><span class="p">,</span> <span class="n">encoding</span><span class="p">))</span>

    <span class="k">return</span> <span class="s">u&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">toenc</span><span class="p">(</span><span class="n">what</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&#39;utf-8&#39;</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; convert to encoding. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">what</span><span class="p">:</span>
        <span class="n">what</span><span class="o">=</span>  <span class="s">u&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">w</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">w</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="n">encoding</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">UnicodeEncodeError</span><span class="p">:</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;can&#39;t encode </span><span class="si">%s</span><span class="s"> to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">what</span><span class="p">,</span> <span class="n">encoding</span><span class="p">))</span>
        <span class="k">return</span> <span class="s">u&quot;&quot;</span>

<span class="k">def</span> <span class="nf">fromenc</span><span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&#39;utf-8&#39;</span><span class="p">,</span> <span class="n">what</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; convert from encoding. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">txt</span><span class="p">:</span>
        <span class="n">txt</span> <span class="o">=</span> <span class="s">u&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">txt</span><span class="p">)</span> <span class="o">==</span> <span class="n">types</span><span class="o">.</span><span class="n">UnicodeType</span><span class="p">:</span>
            <span class="n">t</span> <span class="o">=</span> <span class="n">txt</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="n">encoding</span><span class="p">)</span>
        <span class="n">t</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">txt</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">encoding</span><span class="p">))</span>
    <span class="k">except</span> <span class="ne">UnicodeDecodeError</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">decodeperchar</span><span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">encoding</span><span class="p">,</span> <span class="n">what</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">toascii</span><span class="p">(</span><span class="n">what</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; convert to ascii. &quot;&quot;&quot;</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">&#39;ascii&#39;</span><span class="p">,</span> <span class="s">&#39;replace&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">what</span>

<span class="k">def</span> <span class="nf">tolatin1</span><span class="p">(</span><span class="n">what</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; convert to latin1. &quot;&quot;&quot;</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">&#39;latin-1&#39;</span><span class="p">,</span> <span class="s">&#39;replace&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">what</span>

<span class="k">def</span> <span class="nf">strippedtxt</span><span class="p">(</span><span class="n">what</span><span class="p">,</span> <span class="n">allowed</span><span class="o">=</span><span class="p">[]):</span>

    <span class="sd">&quot;&quot;&quot; strip control characters from txt. &quot;&quot;&quot;</span>

    <span class="n">txt</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">allowed</span> <span class="o">=</span> <span class="n">allowed</span> <span class="o">+</span> <span class="p">[</span><span class="s">&#39;</span><span class="se">\001</span><span class="s">&#39;</span><span class="p">,</span> <span class="s">&#39;</span><span class="se">\002</span><span class="s">&#39;</span><span class="p">,</span> <span class="s">&#39;</span><span class="se">\003</span><span class="s">&#39;</span><span class="p">,</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s">&#39;</span><span class="p">]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">what</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">ord</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">31</span> <span class="ow">or</span> <span class="p">(</span><span class="n">allowed</span> <span class="ow">and</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">allowed</span><span class="p">):</span>
            <span class="n">txt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
    <span class="k">return</span> <span class="s">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">txt</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">uniqlist</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; return unique elements in a list (as list). &quot;&quot;&quot;</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
        <span class="n">j</span> <span class="o">=</span> <span class="n">i</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">j</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">result</span>

<span class="k">def</span> <span class="nf">jabberstrip</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">allowed</span><span class="o">=</span><span class="p">[]):</span>

    <span class="sd">&quot;&quot;&quot; strip control characters for jabber transmission. &quot;&quot;&quot;</span>

    <span class="n">txt</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">allowed</span> <span class="o">=</span> <span class="n">allowed</span> <span class="o">+</span> <span class="p">[</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">,</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s">&#39;</span><span class="p">]</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">text</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">ord</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">31</span> <span class="ow">or</span> <span class="p">(</span><span class="n">allowed</span> <span class="ow">and</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">allowed</span><span class="p">):</span>
            <span class="n">txt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

    <span class="k">return</span> <span class="s">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">txt</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">plugnames</span><span class="p">(</span><span class="n">dirname</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; return all plugin names of plugins in a directory. &quot;&quot;&quot;</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">dirname</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">dirname</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="n">i</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">dirname</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="n">i</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="s">&#39;__init__.py&#39;</span><span class="p">):</span>
                <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">i</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;.py&#39;</span><span class="p">):</span>
            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">[:</span><span class="o">-</span><span class="mf">3</span><span class="p">])</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">result</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;__init__&#39;</span><span class="p">)</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="k">pass</span>

    <span class="k">return</span> <span class="n">result</span>

<span class="k">def</span> <span class="nf">filesize</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; return filesize of a file. &quot;&quot;&quot;</span>

    <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">path</span><span class="p">)[</span><span class="mf">6</span><span class="p">]</span>

<span class="k">def</span> <span class="nf">touch</span><span class="p">(</span><span class="n">fname</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; touch a file. &quot;&quot;&quot;</span>

    <span class="n">fd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">O_WRONLY</span> <span class="o">|</span> <span class="n">os</span><span class="o">.</span><span class="n">O_CREAT</span><span class="p">)</span>
    <span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>  

<span class="k">def</span> <span class="nf">stringinlist</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; check is string is in list of strings. &quot;&quot;&quot;</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>     
        <span class="k">if</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">i</span><span class="p">:</span>  
            <span class="k">return</span> <span class="mf">1</span>

<span class="k">def</span> <span class="nf">stripped</span><span class="p">(</span><span class="n">userhost</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; return a stripped userhost (everything before the &#39;/&#39;). &quot;&quot;&quot;</span> 

    <span class="k">return</span> <span class="n">userhost</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mf">0</span><span class="p">]</span>

<span class="k">def</span> <span class="nf">gethighest</span><span class="p">(</span><span class="n">ddir</span><span class="p">,</span> <span class="n">ffile</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; get filename with the highest extension (number). &quot;&quot;&quot;</span>

    <span class="n">highest</span> <span class="o">=</span> <span class="mf">0</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">ddir</span><span class="p">):</span>

        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">ddir</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="n">i</span><span class="p">)</span> <span class="ow">and</span> <span class="n">ffile</span> <span class="ow">in</span> <span class="n">i</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">seqnr</span> <span class="o">=</span> <span class="n">i</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)[</span><span class="mf">2</span><span class="p">]</span>
            <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="k">try</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="n">seqnr</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">highest</span><span class="p">:</span>
                    <span class="n">highest</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">seqnr</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="k">pass</span>

    <span class="n">ffile</span> <span class="o">+=</span> <span class="s">&#39;.&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">highest</span> <span class="o">+</span> <span class="mf">1</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">ffile</span>

<span class="k">def</span> <span class="nf">waitforqueue</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">10</span><span class="p">,</span> <span class="n">maxitems</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; wait for results to arrive in a queue. return list of results. &quot;&quot;&quot;</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">while</span> <span class="mf">1</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>   
            <span class="n">res</span> <span class="o">=</span> <span class="n">queue</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span>
        <span class="k">except</span> <span class="n">Queue</span><span class="o">.</span><span class="n">Empty</span><span class="p">:</span>
            <span class="k">continue</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">res</span><span class="p">:</span>
            <span class="k">break</span> 

        <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">maxitems</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">result</span><span class="p">)</span> <span class="o">==</span> <span class="n">maxitems</span><span class="p">:</span>
            <span class="k">break</span>

    <span class="k">return</span> <span class="n">result</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.utils.generic</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="exception.html"
                                  title="previous chapter">gozerlib.utils.exception</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="lazydict.html"
                                  title="next chapter">gozerlib.utils.lazydict</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/utils/generic.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="lazydict.html" title="gozerlib.utils.lazydict"
             >next</a> |</li>
        <li class="right" >
          <a href="exception.html" title="gozerlib.utils.exception"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" >gozerlib.utils</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>